//
//  OPBHUDLoadingCircleView.m
//  BOPMSProgress
//
//  Created by zz on 27.11.23.
//

#import "OPBHUDLoadingCircleView.h"
#import "UIImage+OPUD.h"

@interface OPBHUDLoadingCircleView()

@property (strong, nonatomic) UIImageView *greenBackgroundImageView;

@end

@implementation OPBHUDLoadingCircleView

- (instancetype)initWithFrame:(CGRect)frame {
    if (CGRectEqualToRect(frame, CGRectZero)) {
        frame = CGRectMake(0, 0, 32, 32);
    }
    if (self = [super initWithFrame:frame]) {
        [self __setupUI];
        [self __addAnimation];
    }
    return self;
}

- (CGSize)intrinsicContentSize {
    return self.bounds.size;
}

- (void)__setupUI {
    [self addSubview:self.greenBackgroundImageView];
}

- (void)__addAnimation {
    // 旋转
    CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    anima.toValue = @(M_PI*2);
    anima.duration = 0.8;
    anima.repeatCount = MAXFLOAT;
    [self.greenBackgroundImageView.layer   addAnimation:anima forKey:nil];
}

- (UIImageView *)greenBackgroundImageView {
    if (!_greenBackgroundImageView) {
        _greenBackgroundImageView = [[UIImageView alloc] initWithFrame:self.bounds];
        _greenBackgroundImageView.image = [UIImage opudImageNamed :@"greenloading"];
    }
    return _greenBackgroundImageView;
}
- (void)dealloc {
    NSLog(@"=== OPHUDLoadingCircleView dealloc ===");
}


@end
